package com.huilian.iotbox.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huilian.iotbox.admin.dao.MessageLogDao;
import com.huilian.iotbox.admin.service.MessageLogService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.MessageLogDto;
import com.huilian.iotbox.data.enums.SystemRiskConfigTypeEnum;
import com.huilian.iotbox.data.po.MessageLog;
import com.huilian.iotbox.data.po.SystemRiskConfig;
import com.huilian.iotbox.data.vo.MerchantStoreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * MessageLogServiceImpl
 *
 * @Author mineChen
 * @Date 2021/10/29 下午 02:50
 */
@Service
public class MessageLogServiceImpl implements MessageLogService {

    @Autowired
    private MessageLogDao messageLogDao;

    @Override
    public int insert(MessageLog messageLog) {
        return messageLogDao.insert(messageLog);
    }

    @Override
    public void deleteDataBySection(String endDateTime) {
        messageLogDao.deleteDataBySection(endDateTime);
    }

    @Override
    public ServerResponse findMessageLogList(MessageLogDto messageLogDto) {
        if(StringUtils.isEmpty(messageLogDto.getDeviceNo())){
            return ServerResponse.createByErrorMessage("设备号不能为空");
        }

        PageHelper.startPage(messageLogDto.getPageNum(), messageLogDto.getPageSize());
        List<MessageLog> list =  messageLogDao.findMessageLogList(messageLogDto);
        PageInfo pagResult = new PageInfo(list);
        return ServerResponse.createBySuccess(pagResult);
    }
}
